package com.uzai.console.jsonvo.mini;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 小程序用户隐私配置枚举
 * @Auther: liuqi
 * @Date: 2021/8/19 11:22
 * @Description:
 */
public enum MiniPrivacySettingEnum {
    UserInfo("UserInfo", "获取用户信息（微信昵称、头像）,完善用户基本信息"),
    Address("Address", "获取地址，完善用户地址信息"),
    Camera("Camera", "使用摄像头，便于设置用户头像"),
    AlbumWriteOnly("AlbumWriteOnly", "相册（仅写入）权限，仅用于保存图片"),

    ;

    private String key;
    private String desc;

    MiniPrivacySettingEnum(String key, String desc) {
        this.key = key;
        this.desc = desc;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public static MiniPrivacySettingEnum getByKey(String key) {
        if (StringUtils.isBlank(key)) {
            return null;
        }
        for (MiniPrivacySettingEnum type: MiniPrivacySettingEnum.values()) {
            if (type.getKey().equals(key)) {
                return type;
            }
        }
        return null;
    }

    public static List<JSONObject> getSettingList(){
        List privacySettingList = new ArrayList();
        for (MiniPrivacySettingEnum miniPrivacySettingEnum: MiniPrivacySettingEnum.values()) {
            JSONObject privacySettingObject = new JSONObject();
            privacySettingObject.put("privacy_key", miniPrivacySettingEnum.getKey());
            privacySettingObject.put("privacy_text", miniPrivacySettingEnum.getDesc());
            privacySettingList.add(privacySettingObject);
        }
        return privacySettingList;
    }

    public static JSONObject getOwnerSetting(){
        JSONObject ownerSetting = new JSONObject();
        ownerSetting.put("contact_weixin", "Dreamboatxh1314"); //开发者微信号
        ownerSetting.put("notice_method", "其他方式");
        return ownerSetting;
    }

}
